<template>
  <commonCard :titleArr="titleArr" :currnetId="currnetId" @setId="setId">
    <case-assembly
      v-if="currnetId == 1"
      :showBtn="false"
      :detaildata="detaildata"
      @saveRegister="saveRegister"
      @completeFn="completeFn"
    ></case-assembly>
    <prescription v-else-if="currnetId == 2"    
    @completeFn='completeFn'
       :detaildata="detaildata"></prescription>
  </commonCard>
</template>
<script>
import { export_register, complete_jz } from "@/request/api";
import commonCard from "@/components/common/commonCard.vue";
import caseAssembly from "@/components/enterConsultation/case.vue";
import prescription from "@/components/enterConsultation/prescription.vue";
export default {
  components: {
    caseAssembly,
    prescription,
    commonCard,
  },
  data() {
    return {
      detaildata: null,
      currnetId: 1,
      titleArr: [
        {
          id: 1,
          name: "病例",
        },
        {
          id: 2,
          name: "处方",
        },
      ],
    };
  },
  created() {
    if(JSON.stringify(this.$route.params)!=="{}"){

       this.detaildata = this.$route.params
    }else{
      this.$router.go(-1)
    }
  },
  methods: {
    setId(i) {
      this.currnetId = i;
    },
    //保存建议
    saveRegister(e) {
      this.detaildata.diagnosticContent = e;
      if (this.detaildata.diagnosticContent == "") {
        this.$message.error("请输入诊断！");
        return;
      }
      export_register({
        ...this.detaildata,
      })
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.message,
              type: "success",
            });
          } else {
            this.$message.error("保存失败，请重试！");
          }
        })
        .catch((err) => {
          console.log(err, "保存建议错误");
        });
    },
    //结束就诊
    completeFn() {
      this.$confirm("此操作结束就诊, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          complete_jz(this.detaildata.id).then((res) => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
                this.updataExpertInfn()
              setTimeout(() => {
                this.$router.go(-1);
              }, 1000);
            }else{
              this.$message.error('操作失败请重试')
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
  },
};
</script>
<style lang='less' scoped>
.title div {
  color: #858484;
  line-height: 3rem;
  width: 7.5rem;
  height: 2.5rem;
  text-align: center;
  cursor: pointer;
}
.active {
  background: #ffffff;
  border-radius: 0.625rem 0.625rem 0 0;
  font-weight: bold;
  color: #161616 !important;
  font-size: 1.125rem;
  border: none;
}
.el-card {
  border-top: none;
}
</style>